#!/usr/bin/env python3
# -*-coding: utf-8 -*-

import serial  # 导入串口包
import time  # 导入时间包


ser = serial.Serial("/dev/ttyS28",115200,timeout = 5)  # 开启com3口，波特率115200，超时5
ser.flushInput()  # 清空缓冲区

def main():
    fo = open("m.dat","w")
    i=0
    while i< 500:
        count = ser.inWaiting() # 获取串口缓冲区数据
        if count !=0 :
            recv = ser.read(ser.in_waiting).decode("gbk")  # 读出串口数据，数据采用gbk编码
            #print(i)  # 打印一下子
            fo.write(recv)
            i = i + 1
       # time.sleep(0.0001)  # 延时0.1秒，免得CPU出问题
    fo.close()


if __name__ == '__main__':
    main()